(function(e){var t={};BX.namespace("BX.CRM");if(BX.CRM.UFMobile)return;BX.CRM.UFMobile=function(){var t=function(t){this.dialogName="CRMDialog";var i=t["id"];this.controlName=t["controlName"];this.id=BX.util.getRandomString();this.container=BX(i+"Container");this.dropNode=BX.delegate(this.dropNode,this);var n=BX.findChildren(this.container,{tagName:"DL"},false),r,a,o,l,s,d,h={};this.types=[];for(s=0;s<n.length;s++){r=n[s].getAttribute("data-bx-type").toLowerCase();a=this.entities[r];o=BX.findChild(n[s],{tagName:"DT"});if(a){a={type:r,prefix:a.prefix,viewUrl:a.viewUrl,selectUrl:a.selectUrl.replace(/#id#/gi,this.id),title:o?o.innerHTML:r,container:n[s],value:[]};h[r]=a;l=BX.findChildren(n[s],{tagName:"DD"},false);for(d=0;d<l.length;d++){this.bindNode(l[d]);a.value.push(a.prefix+l[d].getAttribute("id"))}}}this.entities=h;if(BX(i+"Add"))BX.bind(BX(i+"Add"),"click",BX.proxy(this.showAdd,this));this.eventName="onCRMEntityWasChosen"+this.id;BXMobileApp.addCustomEvent(e,this.eventName,BX.proxy(this.buildNode,this));return this};t.prototype={entities:{lead:{prefix:"L_",viewUrl:"/mobile/crm/lead/?page=view&lead_id=#id#",selectUrl:"/mobile/crm/search.php?entity=lead"},contact:{prefix:"C_",viewUrl:"/mobile/crm/contact/?page=view&contact_id=#id#",selectUrl:"/mobile/crm/search.php?entity=contact"},company:{prefix:"CO_",viewUrl:"/mobile/crm/company/?page=view&company_id=#id#",selectUrl:"/mobile/crm/search.php?entity=company"},deal:{prefix:"D_",viewUrl:"/mobile/crm/deal/?page=view&deal_id=#id#",selectUrl:"/mobile/crm/search.php?entity=deal"},quote:{prefix:"Q_",viewUrl:"/mobile/crm/quote/?page=view&quote_id=#id#",selectUrl:"/mobile/crm/search.php?entity=quote"}},showAdd:function(e){BX.PreventDefault(e);this.showSelector();return false},showSelector:function(){var t=[],i;for(i in this.entities){if(this.entities.hasOwnProperty(i)){t.push({title:this.entities[i]["title"],callback:function(t){return function(){BXMobileApp.PageManager.loadPageModal({url:t,bx24ModernStyle:true,cache:!e.app.enableInVersion(15)})}}(this.entities[i]["selectUrl"]+"&event="+this.eventName)})}}if(t.length>0)new e.BXMobileApp.UI.ActionSheet({buttons:t},"textPanelSheet").show()},bindNode:function(t){if(BX(t)&&t.parentNode){var i=t.parentNode.getAttribute("data-bx-type").toLowerCase(),n=BX.findChild(t,{tagName:"DEL"});if(this.entities[i]){BX.bind(t,"click",function(t){return function(){e.BXMobileApp.PageManager.loadPageUnique({url:t,bx24ModernStyle:true})}}(this.entities[i]["viewUrl"].replace(/#id#/gi,t.getAttribute("id"))));if(n)BX.bind(n,"click",this.dropNode)}}},buildNode:function(e){var t=e["entityType"];if(this.entities[t]){var i=this.entities[t]["prefix"]+e["id"],n=e["name"];if(!BX.util.in_array(i,this.entities[t]["value"])){var r=BX.create("DD",{attrs:{id:i},html:[BX.util.htmlspecialchars(n),"<del></del>",'<input type="hidden" name="',this.controlName,'" value="'+i+'" />'].join("")});this.entities[t]["container"].appendChild(r);this.entities[t]["value"].push(i);this.bindNode(r);BX.onCustomEvent(this,"onChange",[this,r,"add"])}}},dropNode:function(e){var t=BX.proxy_context||e.target,i=t.parentNode,n=i.parentNode.getAttribute("data-bx-type").toLocaleLowerCase(),r;if(this.entities[n]){n=this.entities[n];r=BX.util.array_search(i.getAttribute("id"),n.value);if(r>=0){n.value.splice(r,1)}}i.parentNode.removeChild(i);BX.onCustomEvent(this,"onChange",[this,i,"delete"]);return BX.PreventDefault(e)}};return t}();BX.CRM.UFMobile.add=function(e){t[e["id"]]=new BX.CRM.UFMobile(e)};BX.Disk.UFMobile.getByName=function(e){for(var i in t){if(t.hasOwnProperty(i)){if(t[i]["controlName"]==e||t[i]["controlName"]==e+"[]"){return t[i]}}}return null}})(window);
//# sourceMappingURL=script.map.js